//
//  MyBankCarListCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/9/8.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class MyBankCarListCell: BaseTableViewCell {
    
    @IBOutlet weak var leftImageView: UIImageView!
    
    @IBOutlet weak var inditorView: UIActivityIndicatorView!
    
    @IBOutlet weak var bottomLabel: UILabel!
    
    @IBOutlet weak var topLabel: UILabel!

    @IBOutlet weak var rightBtn: UIButton!
    

    var model : BankCardInfoModel?{
        
        didSet{
            
            if model == nil {
                return
            }
            
            
            inditorView.startAnimating()
            
            leftImageView.sd_setImage(with: URL(string :model!.bank_image ), placeholderImage: UIImage.defaulLogoImage(), options: []) { (image, _, _, _) in
                self.inditorView.stopAnimating()
                
                
            }
            
            rightBtn.isSelected = model!.isSelect
            
            
            topLabel.text = model?.bank_name
            
            bottomLabel.text = "尾号\(model!.card_no)储蓄卡"
            
            
        }
        
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.white
        rightBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10)
        bottomLabel.textColor = UIColor.dakGray()
        leftImageView.addCornerAndBorder(borderColor: nil, borderWidth: 0, masksToBounds: true, cornerRadius: 36)        // Initialization code
    }
    
    
    
    @IBAction func btnDidTap(_ sender: UIButton) {
        
        if  model!.isSelect  == true {
            return
        }
        
        let temp = viewController() as! MyBankCarListVC
        
        for item in temp.dataModels! {
            item.isSelect = false
        }
        
        model?.isSelect = true
        
//        sender.isSelected = model!.isSelect
        
        temp.plainTableView.reloadData()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
